<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
	</body>
	<script type="text/javascript">
		function getBase64Image(img) {
			var canvas = document.createElement("canvas");
			canvas.width = img.width;
			canvas.height = img.height;
			var ctx = canvas.getContext("2d");
			ctx.drawImage(img, 0, 0, img.width, img.height);
			var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
			var dataURL = canvas.toDataURL("image/" + ext);
			return dataURL;
		}
		var img = "http://qcloud.dpfile.com/pc/bUenU_tAd5lqI-7p-qYED790cwg-EWnscdykRP9_PIYh3ADqnnDmTl4ClHrYoS_QTYGVDmosZWTLal1WbWRW3A.jpg";
		var image = new Image();
		image.setAttribute('crossOrigin', 'anonymous');//允许跨域
		image.src = img;
		image.onload = function() {
			var base64 = getBase64Image(image);
			console.log(base64);
		}
	</script>

</html>